package com.cxlin.base.view.recyclerview.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter4.BaseQuickAdapter
import com.cxlin.base.view.recyclerview.BaseItem

/**
 *
 * @Author: chenxunlin
 * @Date: 2024/4/27 13:52
 */
abstract class BaseAdapter<T : Any, VB : ViewDataBinding>(private val layoutId: Int,private val br:Int) :
    BaseQuickAdapter<T, BaseAdapter.VH<VB>>() {

    class VH<VB : ViewDataBinding>(
        parent: ViewGroup, val binding: VB
    ) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH<VB> {
        return VH(
            parent,
            DataBindingUtil.inflate(
                LayoutInflater.from(parent.context), layoutId, parent, false
            ) as VB
        )
    }

    override fun onBindViewHolder(holder: VH<VB>, position: Int, item: T?) {
        holder.binding.run {
            setVariable(br,item)
            // 立即绑定
            executePendingBindings()
        }

    }

}